
Security News
Meet Socket at Black Hat Europe and BSides London 2025
Socket is heading to London! Stop by our booth or schedule a meeting to see what we've been working on.
detect-file
Advanced tools
Detects if a file exists and returns the resolved filepath.
Install with npm:
$ npm install --save detect-file
Install with yarn:
$ yarn add detect-file
var detect = require('detect-file');
Detect the given filepath if it exists.
Params
filepath {String}: filepath to detect.options {Object}: Additional options.options.nocase {Boolean}: Set this to true to force case-insensitive filename checks. This is useful on case sensitive file systems.returns {String}: Returns the detected filepath if it exists, otherwise returns null.Example
var res = detect('package.json');
console.log(res);
//=> "package.json"
var res = detect('fake-file.json');
console.log(res)
//=> null
When using the nocase option, this library will attempt to detect the filepath with the following methods:
filepath using fs.readdirSync. If successful and filepath is a directory, return the filepath.filepath's directory using fs.readdirSync. If successful, do case insensitive comparasions of the filepath to the files in filepath's directory.fs-exists-sync: Drop-in replacement for fs.existsSync with zero dependencies. Other libs I found either have crucial differences… more | homepage
Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.
(This project's readme.md is generated by verb, please don't edit the readme directly. Any changes to the readme must be made in the .verb.md readme template.)
To generate the readme, run the following command:
$ npm install -g verbose/verb#dev verb-generate-readme && verb
Running and reviewing unit tests is a great way to get familiarized with a library and its API. You can install dependencies and run tests with the following command:
$ npm install && npm test
Brian Woodward
Copyright © 2017, Brian Woodward. Released under the MIT License.
This file was generated by verb-generate-readme, v0.6.0, on August 05, 2017.
fs-extra is a package that builds on the native fs module, providing additional methods to interact with the file system. It includes a method called 'pathExists' which can be used to check if a file exists, similar to detect-file. However, fs-extra offers a broader range of file system operations, making it more versatile.
file-exists is another npm package that offers functionality similar to detect-file, specifically focused on checking the existence of files. While both packages serve a similar purpose, file-exists provides both synchronous and asynchronous APIs, giving developers more flexibility in how they perform the check.
FAQs
Detects if a file exists and returns the resolved filepath.
The npm package detect-file receives a total of 6,511,295 weekly downloads. As such, detect-file popularity was classified as popular.
We found that detect-file demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Socket is heading to London! Stop by our booth or schedule a meeting to see what we've been working on.

Security News
OWASP’s 2025 Top 10 introduces Software Supply Chain Failures as a new category, reflecting rising concern over dependency and build system risks.

Research
/Security News
Socket researchers discovered nine malicious NuGet packages that use time-delayed payloads to crash applications and corrupt industrial control systems.